#改变随机森林中，决策树的数量
import time


from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_wine
import matplotlib.pyplot as plt

wine = load_wine()
print(wine.data.shape)

from sklearn.model_selection import train_test_split, cross_val_score
Xtrain, Xtest, Ytrain, Ytest = train_test_split(wine.data,wine.target,test_size=0.3)
test_res=[]
#实例化模型
current_timestamp1 = time.time()
for i in range(200):
    rfc = RandomForestClassifier(random_state=0, n_estimators=i+1, n_jobs=-1)
    rfcs = cross_val_score(rfc, wine.data, wine.target, cv=10)
    test_res.append(rfcs.mean())
current_timestamp2 = time.time()
print(current_timestamp2-current_timestamp1)
plt.figure(figsize=[20,5])
plt.plot(range(1,201),test_res)
plt.show()




